/*(function(selector,window)
{
	/*--------------拖曳效果----------------
	*原理：标记拖曳状态dragging ,坐标位置iX, iY
	*         mousedown:fn(){dragging = true, 记录起始坐标位置，设置鼠标捕获}
	*         mouseover:fn(){判断如果dragging = true, 则当前坐标位置 - 记录起始坐标位置，绝对定位的元素获得差值}
	*         mouseup:fn(){dragging = false, 释放鼠标捕获，防止冒泡}
	*
	var window=window;
	var document=window.document;
	
	var dragging = false;
	var iX, iY;
	selector.mousedown(function(e) {
		dragging = true;
		iX = e.clientX - this.offsetLeft;
		iY = e.clientY - this.offsetTop;
		this.setCapture && this.setCapture();
		return false;
	});
	document.onmousemove = function(e) {
		if (dragging) {
		var e = e || window.event;
		var oX = e.clientX - iX;
		var oY = e.clientY - iY;
		$("#chat").css({"left":oX + "px", "top":oY + "px"});
		return false;
		}
	};
	$(document).mouseup(function(e) {
		dragging = false;
		selector[0].releaseCapture();
		e.cancelBubble = true;
	})
})($("#bar"),window);
*/

var params = {
	left: 0,
	top: 0,
	currentX: 0,
	currentY: 0,
	flag: false
};
//获取元素css属性值
var getCss = function(o,key){
	return o.currentStyle? o.currentStyle[key] : document.defaultView.getComputedStyle(o,false)[key]; 	
};

//鎷栨嫿鐨勫疄鐜�
var startDrag = function(bar, target, callback){
	if(getCss(target, "left") !== "auto"){
		params.left = getCss(target, "left");
	}
	if(getCss(target, "top") !== "auto"){
		params.top = getCss(target, "top");
	}
	//o鏄Щ鍔ㄥ璞�
	bar.onmousedown = function(event){
		params.flag = true;
		if(!event){
			event = window.event;
			//阻止选中事件
			bar.onselectstart = function(){
				return false;
			}  
		}
		var e = event;
		params.currentX = e.clientX;
		params.currentY = e.clientY;
	};
	document.onmouseup = function(){
		params.flag = false;	
		if(getCss(target, "left") !== "auto"){
			params.left = getCss(target, "left");
		}
		if(getCss(target, "top") !== "auto"){
			params.top = getCss(target, "top");
		}
	};
	document.onmousemove = function(event){
		var e = event ? event: window.event;
		if(params.flag){
			var nowX = e.clientX, nowY = e.clientY;
			var disX = nowX - params.currentX, disY = nowY - params.currentY;
			target.style.left = parseInt(params.left) + disX + "px";
			target.style.top = parseInt(params.top) + disY + "px";
		}
		
		if (typeof callback == "function") {
			callback(parseInt(params.left) + disX, parseInt(params.top) + disY);
		}
	}	
};

(startDrag)($("#bar").get(0),$("#chating").get(0));
/*(function()
{
	allpull();
})();
*/